<?php

declare(strict_types=1);

namespace app\shop\model\attr;

use sheep\model\Common;
use think\model\concern\SoftDelete;

class ShopTypeServiceProject extends Common
{
    use SoftDelete;

    protected $deleteTime = 'delete_time';
    protected $name = 'shop_type_service_project';
    protected $pk = false;

    // 服务项目/规格添加
    public function serviceCreate($params)
    {
        $serviceModel = self::where(['shop_type_id' => $params['shop_type_id']])->find();
        if ($serviceModel) {
            $serviceModel->delete();
        }
        if (!empty($params['service'])) {
            foreach ($params['service'] as $k => $item) {
                if (empty($item['shop_type_id'])) {
                    $params['service'][$k]['shop_type_id'] = $params['shop_type_id'];
                }
            }
        }
        return $this->saveAll($params['service']);
    }

    // 模型关联
    public function children()
    {
        // todo
    }
}
